#ifndef _TOS_SECURE_CONTEXT_H_
#define  _TOS_SECURE_CONTEXT_H_

#include "tos_compiler.h"
#include "tos_ktypes.h"
#include "tos_config.h"

/**@todo delete these include file */
__CDECLS_BEGIN

/**
 * @brief Structure to represent a secure context.
 *
 * @note Since stack grows down, pucStackStart is the highest address while
 * pucStackLimit is the first address of the allocated memory.
 */
typedef struct k_secure_ctx_st
{
    k_task_t* curr_psp; /**< Current value of process stack pointer (PSP). */
    k_task_t* psp_limit;          /**< Last location of the stack memory (PSPLIM). */
    k_task_t* psp_start;          /**< First location of the stack memory. */
    void * task_handler;              /**< Task handle of the task this context is associated with. */
} k_secure_ctx_t;

/**
 * @brief TobudOS kernel handle for a secure context.
 */
typedef uint32_t k_secure_ctx_handle_t;

#if TOS_CFG_TRUSTZONE_EN > 0u

#define K_SECURE_CTX_INVALID_ID     0U
#define K_SECURE_CTX_NO_STACK       0U /* PSP value when no secure context is loaded. */

__KNL__ void tos_secure_ctx_init(void);

__KNL__ k_secure_ctx_handle_t tos_secure_ctx_alloc(uint32_t size, void *owner);

__KNL__ void tos_secure_ctx_free(k_secure_ctx_handle_t handle, void *owner);

__KNL__ void tos_secure_ctx_load(k_secure_ctx_handle_t handle, void *owner);

__KNL__ void tos_secure_ctx_save(k_secure_ctx_handle_t handle, void *owner);

#endif /* TOS_CFG_TRUSTZONE_EN */

__CDECLS_END

#endif /* _TOS_SECURE_CONTEXT_H_ */
